'''import unittest
from api.login import LoginAPI
import config
import json
from parameterized import parameterized


# 读取json文件
def read_json_file():
    test_data = []
    json_file = config.BASE_PATH + "/data/login.json"
    with open(json_file, encoding="utf-8") as f:
        json_data = json.load(f)
        for i in json_data:
            login_data = i.get("login_data")
            status_code = i.get("status_code")
            success = i.get("success")
            code = i.get("code")
            message = i.get("message")
            test_data.append((login_data, status_code, success, code, message))
    return test_data


class TestLoginAPI(unittest.TestCase):
    def setUp(self) -> None:
        self.login_api = LoginAPI()

    def tearDown(self) -> None:
        pass

    def test01_add(self):
        result = LoginAPI().add(1, 1)
        print(result)

    @parameterized.expand(read_json_file())
    def test02_login(self, login_data, status_code, success, code, message):
        response = self.login_api.login(login_data)
        print(response.json())
        # 断言
        self.assertEqual(status_code, response.status_code)
        self.assertEqual(success, response.json().get("success"))
        self.assertEqual(code, response.json().get("code"))
        self.assertIn(message, response.text)'''
import json
import requests
import unittest
import config
from api.login import LoginAPI
from parameterized import parameterized
def read_json_file():
    with open(config.BASE_PATH+"/data/login.json",encoding="utf_8")as f:
        json_data=json.load(f)
        test_data=[]
        for i in json_data:
            login_data=i.get("login_data")
            status_code=i.get("status_code")
            success=i.get("success")
            code=i.get("code")
            message=i.get("message")
            test_data.append((login_data,status_code,success,code,message))
        return test_data
class TestLoginAPI(unittest.TestCase):
    def setUp(self) -> None:
        self.login_add=LoginAPI()
    def tearDown(self) -> None:
        pass
    def test01_add(self):
        result=self.login_add.add(1,1)
        print(result)
    @parameterized.expand(read_json_file())
    def test02_login(self,login_data,status_code,success,code,message):
        response=self.login_add.longin(login_data)
        self.assertEqual(status_code,response.status_code)
        self.assertEqual(success,response.json().get("success"))
        self.assertEqual(code,response.json().get("code"))
        self.assertIn(message,response.json().get("message"))
